﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Drawing;
using MenuItem = System.Windows.Forms.MenuItem;
using Image = System.Drawing.Image;
using System.Diagnostics;

namespace DemoMode.Views
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        internal static ViewModels.MainWindowViewModel ViewModel;
        public MainWindow()
        {
            InitializeComponent();
            ViewModel = new ViewModels.MainWindowViewModel(this);
            DataContext = ViewModel;
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Settings.Default.IsAutoEnterDemoMode = ViewModel.IsAutoEnterDemoMode;
            Settings.Default.IntervalTime = ViewModel.IntervalTime;
            Settings.Default.KeyToPress = ViewModel.KeyToPress;
            Settings.Default.Mode = ViewModel.IsDefaultMode;
            Settings.Default.IsWorkWhenSessionLock = ViewModel.IsWorkWhenSessionLock;
            Settings.Default.Save();
            ViewModel.NotifyIcon.Dispose();
        }

        private void UITextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            switch((sender as System.Windows.Controls.TextBox).Name)
            {
                case "KeySettingBox":
                    ViewModel.Key = e.Key;
                    break;
            }
        }

        private void Hyperlink_Click(object sender, RoutedEventArgs e)
        {
            var p = new Process
            {
                StartInfo=new ProcessStartInfo((sender as Hyperlink).NavigateUri.ToString()),
            };
            p.Start();
        }
    }
}
